<?php
class Control_Game_getPlatformByGame {

	function getPlatformByGame() {
		$game 		= MooForm::request('game');
		$type 		= MooForm::request('type');
		$gameLangConf = MooConfig::get('game_lang.zh_en');
		if($gameLangConf[$game]) {
			$game = $gameLangConf[$game];
		}
		$url = MooConfig::get('main.url.fetch_game');
		
		if($type == "callback") {
			$channel_lang = MooConfig::get("callbackchannel_lang.{$game}.en_zh");
			$channels = array();
			foreach($channel_lang as $key => $val) {
				$channels[] = $val;
			}
		} else {
			$channel_lang = MooConfig::get("channel_lang.{$game}.en_zh");
		}
		$result = MooUtil::curl_send($url);
		$resultArr = MooJson::decode($result, true);
		$gameConf = array();
		if ($resultArr) {
			foreach ($resultArr as $key => $val) {
				$gameConf[$val['game']]['platform'] = explode(',', $val['platform']);
				$totalChannels = explode(',', $val['channel']);
				
				// 中英翻译
				foreach($totalChannels as $k => $v) {
					if($channel_lang[$v]) {
						$totalChannels[$k]  = $channel_lang[$v];
					}
				}
				if($type == "callback") {
					$gameConf[$val['game']]['channel'] 	= $channels;
				} else {
					$gameConf[$val['game']]['channel'] 	= $totalChannels;
				}
			}
		}
		
		$userName = MooObj::get('User')->getUserName();
		$channelLimit = MooConfig::get('channel_limit');
		if(!empty($channelLimit[$game][$userName])) {
			$res = $channelLimit[$game][$userName];
		} else {
			$res = $gameConf[$game];
		}
		
		$rs = MooJson::encode($res);
		exit($rs);
	}
}
